//
//  ACAppointmentLiveCell.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/29.
//

#import "ACAppointmentLiveCell.h"

@interface ACAppointmentLiveCell ()

@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UIImageView *liveCoverImage;
@property (weak, nonatomic) IBOutlet UILabel *liveTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *liverNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *liveTimeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *livePwdIcon;
@property (weak, nonatomic) IBOutlet UIButton *toLiveBtn;
@end


@implementation ACAppointmentLiveCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 10;
    
    self.liveCoverImage.backgroundColor = [UIColor grayColor];
    self.liveCoverImage.layer.cornerRadius = 4;
    self.liveCoverImage.layer.masksToBounds = YES;
    
    self.toLiveBtn.layer.masksToBounds = YES;
    self.toLiveBtn.layer.cornerRadius = 10;
    @weakify(self)
    [[self.toLiveBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        if (self.clickActionHandler) {
            self.clickActionHandler();
        }
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setModel:(ACLiveModel *)model{
    _model = model;
    NSString *coverStr = model.img;
    if ((![coverStr startsWith:@"http://"] && ![coverStr startsWith:@"https://"] ) && coverStr != nil) {
        coverStr = [@"http://" stringByAppendingString:coverStr];
    }
    NSURL *coverURL = [NSURL URLWithString:coverStr];
    [self.liveCoverImage sd_setImageWithURL:coverURL];
    self.liveTitleLabel.text = model.title;
    if ([model.status isEqualToString:@"0"]) {
        [self.toLiveBtn setTitle:@"审核中" forState:UIControlStateNormal];
    }else if ([model.status isEqualToString:@"1"]){
        [self.toLiveBtn setTitle:@"开始路演" forState:UIControlStateNormal];
    }else if([model.status isEqualToString:@"3"]){
        [self.toLiveBtn setTitle:@"直播中" forState:UIControlStateNormal];
    }else if ([model.status isEqualToString:@"4"]){
        [self.toLiveBtn setTitle:@"已结束" forState:UIControlStateNormal];
    }
    self.liveTimeLabel.text = model.start_time;
    BOOL isNeedPwd = [_model.enable_password boolValue];
    NSString *pwdIconStr = isNeedPwd ? @"icon_live_pwd":@"icon_live_nopwd";
    self.livePwdIcon.image = [UIImage imageWithName:pwdIconStr bundle:ACLiteAVUISDK targetClass:[self class]];
    ACLiveCreaterModel *userModel = _model.user;
    self.liverNameLabel.text = userModel.nickname;
    [self.livePwdIcon setHidden:YES];
}

-(void)setBookedModel:(ACBookedLiveModel *)bookedModel{
    _bookedModel = bookedModel;
    self.model = _bookedModel.shows;
    int status = [_bookedModel.status intValue];
    if (status == 0) {
        [self.toLiveBtn setTitle:@"审核中" forState:UIControlStateNormal];
    }else if (status == 1){
        [self.toLiveBtn setTitle:@"观看" forState:UIControlStateNormal];
    }
    [self.livePwdIcon setHidden:NO];
}

@end
